package com.poizon.infrastructure.center.config.starter.apollo;

import cn.hutool.core.lang.Assert;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;

/**
 * 注册apollo监听器
 */
@Slf4j
@AllArgsConstructor
public class ApolloChangeListenerRegister implements ApplicationRunner {
    private ApolloChangeListener configChangeListener;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        Assert.notNull(configChangeListener);

        log.info(">注册apollo配置变更监听器");
        Config config = ConfigService.getAppConfig();
        config.addChangeListener(configChangeListener);
    }
}
